"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Daily_ResourceDao = void 0;
const DbConfig_1 = require("../../src/config/DbConfig");
const DaoBase_1 = require("../../src/engine/dao/DaoBase");
const DateUtil_1 = require("../../src/engine/utils/DateUtil");
const Logger_1 = require("../../src/engine/utils/Logger");
const MysqlManager_1 = require("../../src/engine/utils/MysqlManager");
class Daily_ResourceDao extends DaoBase_1.DaoBase {
    static insert_daily_resource() {
        return __awaiter(this, void 0, void 0, function* () {
            let client = yield MysqlManager_1.MysqlManager.instance.getDb(this.DB_NAME);
            let sql = "select sum(gems) as gems,sum(coins) as coins,sum(meilis) as meilis, sum(income) as income from t_users";
            let sqlParams = [];
            let results = yield client.queryPromise(sql, sqlParams);
            Logger_1.Logger.log("get_main_statistics_info=", results);
            let resultObj = results[0];
            sql = "replace into t_daily_resource(date, gems, coins, meilis, income) values(?,?,?,?,?)";
            sqlParams = [DateUtil_1.default.formatDateStr3(DateUtil_1.default.now()), resultObj["gems"], resultObj["coins"], resultObj["meilis"], resultObj["income"]];
            yield client.queryPromise(sql, sqlParams);
        });
    }
    static get_daily_resource() {
        return __awaiter(this, void 0, void 0, function* () {
            let client = yield MysqlManager_1.MysqlManager.instance.getDb(this.DB_NAME);
            let sql = "select * from t_daily_resource";
            let sqlParams = [];
            let results = yield client.queryPromise(sql, sqlParams);
            sql = "select sum(gems) as gems,sum(coins) as coins,sum(meilis) as meilis, sum(income) as income  from t_users";
            let todayResult = yield client.queryPromise(sql, sqlParams);
            Logger_1.Logger.log("get_main_statistics_info=", results);
            Logger_1.Logger.log("get_main_statistics_info=", todayResult);
            Logger_1.Logger.log("get_daily_resource=", results);
            let tempObj = todayResult[0];
            tempObj["date"] = DateUtil_1.default.now();
            results.push(tempObj);
            return results;
        });
    }
    static clear(delete_time) {
        return __awaiter(this, void 0, void 0, function* () {
            let client = yield MysqlManager_1.MysqlManager.instance.getDb(this.DB_NAME);
            let sql = "delete from t_daily_resource where date < ?";
            let sqlParams = [DateUtil_1.default.formatDateStr3(delete_time)];
            yield client.queryPromise(sql, sqlParams);
        });
    }
}
exports.Daily_ResourceDao = Daily_ResourceDao;
Daily_ResourceDao.DB_NAME = DbConfig_1.DbConfig.Db_Name.db_admin;
